﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace FSUtility
{
    /// <summary>
    /// 和UI中的Form相关操作
    /// </summary>
    public class UIForm<T> where T : Form
    {
        /// <summary>
        /// 查找已经打开的Form
        /// 一般用于WinForm开发中
        /// 查找Show的Form
        /// </summary>
        /// <param name="findForm">待查找的Form</param>
        /// <returns>是否已经Show了指定Form</returns>
        public bool FindOpenedForm(ref T findForm)
        {
            //遍历所有打开的Form
            foreach (Form item in Application.OpenForms)
            {
                //通过Typeof对比确定
                if (item.GetType() == typeof(T))
                {
                    findForm = item as T;
                    return true;
                }
            }
            return false;
        }
    }
}
